<?php
/**
 * 系統名稱: Lotto 系統
 * 檔案說明: 專案管理-修改
 * $Author$
 * $Id$
 *
 */
$intNewUpdateTime = (int)$_data["NewUpdateTime"];
$intGambleID = (int)$_data["GambleID"];
$strBT = trim($_data["Bet_Type"]);

//不含過關
$strSQL = "select * from `bet_TodayGame".$intLID."` where `GambleID` = '".$intGambleID."' and `Bet_Type` != 15 and `UpdateTime` > ".$intNewUpdateTime." order by `Bet_Type`, `Number`";
if(!$RS = PMA_mysql_query($strSQL, $$_Conn)){
	$GLOBALS["errormessage"] = "Find TodayGame Data Error!!";
	$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($$_Conn)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
	ErrMsgOutputHTML("Error", "", 1);
}
/*if(PMA_mysql_num_rows($RS) == 0){
	$GLOBALS["errormessage"] = "No TodayGame Data!!";
	ErrMsgOutputHTML("Error", "", 1);
}*/

$arrUpBT = array();
while($Rows = PMA_mysql_fetch_object($RS)){
	$strCon .= "parent.arrGame[".$Rows -> Bet_Type."][".$Rows -> Number."]={GID:".$Rows -> GambleID.
		",BT:".$Rows -> Bet_Type.
		",Num:".$Rows -> Number.
		",Odds:".round($Rows -> Odds, 3).
		",isStop:".$Rows -> isStopBet.
		",tolW:".$Rows -> tolWager.
		",tolS:".round($Rows -> tolStake, 3).
		",tolP:".round($Rows -> tolPayOff, 3).
		",tolC:".round($Rows -> tolCommission, 4).
		",tolRS:".round($Rows -> tolRealStake, 3).
		",tolRP:".round($Rows -> tolRealPayOff, 3).
		",tolSS:".round($Rows -> tolSuppleStake, 3).
		",tolSP:".round($Rows -> tolSupplePayOff, 3).
		",tolSC:".round($Rows -> tolSuppleCommission, 4).
		"};\n";

	if($intNewUpdateTime < $Rows -> UpdateTime)$intNewUpdateTime = $Rows -> UpdateTime;
	$arrUpBT[$Rows -> Bet_Type] = $Rows -> Bet_Type;
}

//過關的處理
$strSQL = "select a.Bet_Type as Bet_Type, a.Number as Number, SUM(b.MemStake) as tolStake, SUM(b.MemPayOff) as tolPayOff, SUM(b.MemStake*MemExchangeRate*DirectorRate) as tolRealStake, SUM(b.MemPayOff*MemExchangeRate*DirectorRate) as tolRealPayOff, COUNT(*) as tolWager, SUM(b.MemStake*MemExchangeRate*DirectorRate*DirectorCommission) as tolCommission  from `bet_ParlaysNumber` a, `bet_BetListTmp` b where a.BetListID = b.ID and b.GambleID = '".$intGambleID."' and b.Bet_Type = 15 group by a.Bet_Type, a.Number";
if(!$RS = PMA_mysql_query($strSQL, $$_Conn)){
	$GLOBALS["errormessage"] = "Find TodayGame Data Error!!";
	$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($$_Conn)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
	ErrMsgOutputHTML("Error", "", 1);
}
$intNo = 0;
while($Rows = PMA_mysql_fetch_object($RS)){
	$strCon .= "parent.arrGame[15][".$Rows -> Bet_Type.$Rows -> Number."]={GID:".$intGambleID.
		",BT:".$Rows -> Bet_Type.
		",Num:".$Rows -> Number.
		",tolW:".$Rows -> tolWager.
		",tolS:".round($Rows -> tolStake, 3).
		",tolP:".round($Rows -> tolPayOff, 3).
		",tolC:".round($Rows -> tolCommission, 4).
		",tolRS:".round($Rows -> tolRealStake, 3).
		",tolRP:".round($Rows -> tolRealPayOff, 3).
		"};\n";
	$intNo++;
}
$arrUpBT[15] = 15;


/*=================================================================*/
header("Cache-Control: no-store, no-cache, must-revalidate");	  // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");															  // HTTP/1.0
?><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script language="JavaScript">
<!--
<?php 
print $strCon."\n";
print "parent.isEmergency = ".((empty($_isStopAllBet))?"0":$_isStopAllBet).";\n";
print "parent.changEmergency();\n";
print "parent.PageConfig.NewUpdateTime = ".$intNewUpdateTime.";\n";
print "parent.PageConfig.UpdateBetType = '".implode(",", $arrUpBT)."';\n";

print "parent.setOddsObject();\n";
?>
//-->
</script>